﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SharePoint2007Migration.Domain.Collections
{
    // should be sealed
    public class BaseIssueCollection<T>: List<T> where T : IBaseIssue
    {

        public string ContentDbName 
        {
            get 
            {
                if (this.Count != 0)
                    return this[0].ContentDbName;
                else return string.Empty;
            }
            
        }

        public IssueCollection ToIssueCollection()
        {
            IssueCollection toRetun = new IssueCollection();

            foreach (IBaseIssue item in this)
            {
                toRetun.Add((BaseIssue)item);
            }
            return toRetun;
        }


        public MissingAssemblyIssueCollection GetAllMissingAssemblyIssues()
        {
            MissingAssemblyIssueCollection toReturn = new MissingAssemblyIssueCollection();
            foreach (IBaseIssue item in this)
                if (item.Category== IssueCategory.MissingAssembly)
                    toReturn.Add(new MissingAssemblyIssue(item));
            return toReturn;
        }

        public MissingFeatureIssueCollection GetAllFeatureIssues()
        {
            MissingFeatureIssueCollection toReturn = new MissingFeatureIssueCollection();
            foreach (IBaseIssue item in this)
                if (item.Category == IssueCategory.MissingFeature)
                    toReturn.Add(new MissingFeatureIssue(item));
            return toReturn;
        }


        public MissingSetupFileIssueCollection GetAllSetupFileIssues()
        {
            MissingSetupFileIssueCollection toReturn = new MissingSetupFileIssueCollection();
            foreach (IBaseIssue item in this)
                if (item.Category == IssueCategory.MissingSetupFile)
                    toReturn.Add(new MissingSetupFileIssue(item));
            return toReturn;
        }

        public MissingWebPartIssueCollection GetAllWebPartIssues()
        {
            MissingWebPartIssueCollection toReturn = new MissingWebPartIssueCollection();
            foreach (IBaseIssue item in this)
                if (item.Category == IssueCategory.MissingWebPart)
                    toReturn.Add(new MissingWebPartIssue(item));
            return toReturn;
        }
       
    }
}
